<template>
	<view class="page-index">
		<view class="hd">
			<view class="info">
				<view class="info-hd">付款给</view>
				<view class="info-bd">{{currentHospital.name}}</view>
			</view>
			<view class="info-icon">
				<img class="info-icon-img" src="@/static/images/info-icon.png" alt="">
			</view>
			<view class="bg"></view>
		</view>
		<view class="bd">
			<view class="box">
				<view class="box-hd">
					<view class="box-hd-label">费用总额</view>
					<view class="box-hd-value">{{feeDetail.feeSumamt}}元</view>
				</view>
				<view class="box-bd">
					<view class="box-item">
						<view class="box-bd-label">医保基金支付</view>
						<view class="box-bd-value">{{feeDetail.fundPay}}元</view>
					</view>
					<view class="box-item">
						<view class="box-bd-label">个人账户支付</view>
						<view class="box-bd-value">{{feeDetail.psnAcctPay}}元</view>
					</view>
					<!-- <view class="box-item">
						<view class="box-bd-label">其他抵扣金额</view>
						<view class="box-bd-value">{{feeDetail.othFeeAmt}}元</view>
					</view> -->
				</view>
				<view class="box-ft">
					<view class="box-ft-label">现金支付</view>
					<view class="box-ft-value">{{feeDetail.ownPayAmt}}元</view>
				</view>
				<!-- <view class="box-append" @click="handleActionsheet">
					查看明细
				</view> -->
			</view>
			<view class="bd-append">
				<i class="bd-append-icon"></i>
				<view class="bd-append-text">医保移动支付</view>
			</view>
		</view>
		<view class="ft">
			<view class="pay">
				<view class="pay-label">您还需支付：</view>
				<view class="pay-value">¥{{feeDetail.feeSumamt}}</view>
			</view>
			<view class="btn" @click="postOrder()">去支付</view>
		</view>
		<view class="actionsheet" v-show="actionsheetVisible">
			<view class="actionsheet-mask" @click="handleActionsheet"></view>
			<view class="actionsheet-panel">
				<view class="actionsheet-hd">
					<view class="actionsheet-hd-tt">处方明细</view>
					<i class="actionsheet-icon-close" @click="handleActionsheet"></i>
				</view>
				<view class="actionsheet-bd">
					<view class="actionsheet-box" v-for="item in prescriptionList" :key="item.title">
						<view class="actionsheet-box-hd">{{item.title}}</view>
						<view class="actionsheet-box-bd">
							<view class="actionsheet-box-item" v-for="boxItem in item.list" :key="boxItem.label">
								<view class="actionsheet-box-item-label-wrap">
									<view class="actionsheet-box-item-label">{{boxItem.label}}</view>
									<view class="actionsheet-box-item-sublabel">{{boxItem.subLabel}}</view>
								</view>
								<view class="actionsheet-box-item-value" :class="[boxItem.highlight ? 'em' : '']">
									{{boxItem.value}}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	import {
		encrypt,
		decrypt
	} from '@/utils/sm4Util.js'
	import {
		uldFeeInfoWX,
		ybUnifiedOrder
	} from "@/api/pay/index.js"
	export default {
		name: 'PageIndex',
		data() {
			return {
				params: {
					payAuthNo: "",
					cfhList: "",
					idNum: "",
				},
				currentHospital: {
					name: '',
					hospitalCode: ''
				},
				feeDetail: {}, //费用明细
				prescriptionList: [{
						title: '就诊信息',
						list: [{
								label: '门诊类别',
								value: '门(急)诊'
							},
							{
								label: '门诊科室',
								value: '普通内科'
							},
							{
								label: '医生姓名',
								value: '张三'
							},
							{
								label: '处方时间',
								value: '2021/06/08 14:54:00'
							},
							{
								label: '费用总额',
								value: '368.50元',
								highlight: true
							},
						]
					},
					{
						title: '诊断信息',
						list: [{
								label: '诊断名称',
								value: '外伤肿胀'
							},
							{
								label: '诊断编号',
								value: 'E3D.25'
							},
						]
					},
					// {
					//   title: '特殊信息',
					//   list: [
					//     { label: '病情名称', value: '高血压' },
					//     { label: '病情编号', value: '2220003495858' },
					//   ]
					// },
					{
						title: '费用信息',
						list: [{
								label: '万通胫骨贴*1',
								subLabel: '8g/片/3',
								value: '37.80元'
							},
							{
								label: '阿莫西林*1',
								subLabel: '8g/片/3',
								value: '7.80元'
							},
						]
					},
					// {
					//   title: '其他抵扣金额',
					//   list: [
					//     { label: '住院押金抵扣', value: '50元' },
					//     { label: '医院负担金额抵扣', value: '50元' },
					//   ]
					// },
				],
				actionsheetVisible: false,
				openid: '',
			}
		},
		onLoad(options) {
			let openid = uni.getStorageSync('openid') || ''
			this.openid = openid
			uni.showLoading({
				title: '加载中',
				mask: true,
			});
			if (options.params) {
				this.params = JSON.parse(options.params);
			}
			this.postFee();
			let hospital = uni.getStorageSync('hospital');
			this.currentHospital = JSON.parse(hospital);
		},
		methods: {
			handleActionsheet() {
				this.actionsheetVisible = !this.actionsheetVisible;
			},
			// 费用明细上传
			postFee() {
				uldFeeInfoWX({
					payAuthNo: this.params.payAuthNo,
					cfhList: this.params.cfhList,
					idNum: this.params.idNum,
				}).then(res => {
					uni.hideLoading();
					if (res.data.result && res.data.result != 0) {
						this.$msg(res.data.message);
					} else {
						this.feeDetail = res.data;
					}
				});
			},
			// 微信医保统一下单请求
			postOrder() {
				uni.showLoading({
					title: '加载中',
					mask: true,
				});
				var parmsData = {
					"hospitalCode": this.currentHospital.hospitalCode, // 医院编码
					"openId": this.openid, // 微信openid
					"bh": JSON.parse(uni.getStorageSync('currentVisitCard')).cardNum, // 卡号/住院号
					"name": this.params.user_name, // 姓名
					"idNum": this.params.idNum, // 身份证
					"recipelNum": this.params.cfhList, // 处方号（门诊业务专用字段
					"elecCashFee": this.feeDetail.ownPayAmt, // 现金支付
					"elecInsuranceFee": this.feeDetail.fundPay, // 医保基金支付
					"psnAcctPay": this.feeDetail.psnAcctPay, // 医保个人账户支付
					"orderAmount": this.feeDetail.feeSumamt, // 总金额
					"orderDesc": "微信医保支付", // 订单描述（医卡通，预约，门诊支付 住院押金）
					"payType": "weChat", // 支付类型（weChat:微信 Alipay:支付宝）
					"orderType": "31", // 订单类型（1医卡通，2预约，3门诊支付 4住院押金 31 医保支付）
					"payAuthNo": this.params.payAuthNo, // 支付授权码
					"payOrdId": this.feeDetail.payOrdId, // 支付订单号
					"setlLatlnt": this.params.log_lat, // 用户经纬度
					"latitude": this.params.log_lat.latitude,
					"longitude": this.params.log_lat.longitude,
					"medOrgOrd": this.feeDetail.medOrgOrd, // 医疗机构订单号
					"payToken": this.feeDetail.payToken, // 支付token
					"insuplcAdmdvs": this.feeDetail.insuplcAdmdvs ,// 参保地区
					// 支付后回跳的页面，后端配置-前端不需要传
					// "returnUrl": "https://www.lanbodianzi.com/palmHospitalHNSHJTH5/pages/order/orderDetail/orderDetail"
				}
				console.log('parmsData=', parmsData)
				let param = {
					params: encrypt(JSON.stringify(parmsData))
				}
				ybUnifiedOrder(param).then(res => {
					uni.hideLoading();
					let resData = JSON.parse(res.msg);
					window.location.href = resData.pay_url;
					console.log('resData===', resData)
				});
			},
		}
	}
</script>

<style scoped>
	@import './index.css';
	@import './actionsheet.css';
</style>